import App from './App.vue'
import Vue from 'vue'
import router from './router'
import store from './store'
import Axios from 'axios'
// import axiosRequest from '@/utils/request.js'
import Swiper from 'swiper'
import "weui"
// import scroll from 'vue-seamless-scroll'
// Vue.use(scroll)

import 'swiper/dist/css/swiper.min.css'
import './../static/css/reset.css'
import './../static/css/common.css'
import './../static/css/aside.css'
import './../static/css/fonts/iconfont.css'
import MD5 from 'blueimp-md5'
Vue.prototype.MD5 = MD5
import {getCookie} from  './utils/index.js'
Vue.prototype.axios= Axios
Vue.prototype.Swiper = Swiper
Vue.config.productionTip = false
var baseSecret ='71clouddangjiang'
var currentTime = +new Date()
var token =localStorage.getItem('token')||store.state.app.loginState.token|| 0
var uid= localStorage.getItem('uid') ||store.state.app.loginState.uid || 0
var secret =MD5(`${baseSecret}${token}${currentTime}${uid}`)
var baseUrl =`secret=${secret}&uid=${uid}&time=${currentTime}`
Vue.prototype.baseUrl =baseUrl
router.beforeEach(function (to,from,next) {
  if (to.meta.requireAuth) {  // 判断该路由是否需要登录权限
    if (store.state.app.loginState.uid && store.state.app.loginState.token ||(localStorage.getItem('uid'))&&localStorage.getItem('token')) {  // 通过vuex state获取当前的token是否存在
      var baseSecret ='71clouddangjiang'
      var currentTime = +new Date()
      var token =localStorage.getItem('token')||store.state.app.loginState.token|| 0
      var uid = localStorage.getItem('uid') ||store.state.app.loginState.uid || 0
      var secret =MD5(`${baseSecret}${token}${currentTime}${uid}`)
      var baseUrl =`secret=${secret}&uid=${uid}&time=${currentTime}`
      Vue.prototype.baseUrl =baseUrl
      next();
    }
    else {
      next({
        path: '/loginPage',
        // query: {redirect: to.fullPath}  // 将跳转的路由path作为参数，登录成功后跳转到该路由
      })
    }
  }
  else {
    next();
  }
})

// router.beforeEach(function (to,from,next) {
//   // console.log(to.name)
//   if(store.state.app.loginState.uid||localStorage.getItem('uid')&&localStorage.getItem('userAccount')){
//       next()
//   }else{
//     if(to.path=='/'||to.path=='/regeister'||to.path=='/resetPassword'){
//         next()
//     }else{
//       next('/')
//     }
//   }
// })

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
